<template>
	<view style="display: flex;">
		<view v-if="sConf.maxLeft" :style="{width: sConf.toLeft +'px'}"
			style="background-color: #4c4c4c;padding: 10px;height: 64px;display: flex;align-items: center;gap: 10px;">
			<image src="/static/logo.png" mode="scaleToFill" style="width: 48px;height: 48px;"></image>
			<text class="login-title admin-font-yahe">{{sConf.appName}}</text>
			<view style="flex: 1;"></view>
		</view>
		<view v-else
			style="background-color: #4c4c4c;padding: 10px;height: 64px;display: flex;flex-direction: column;justify-content: center;align-items: center;">
			<image src="/static/logo.png" mode="scaleToFill" style="width: 24px;height: 24px;"></image>
		</view>
		<view class="top-right-block"
			style="display: flex;justify-content: space-between;align-items: center;width: 100%;padding: 5px 10px;">
			<view>
				<uni-icons :type="sConf.maxLeft?'bars':'list'" size="32"
					@tap="sConf.maxLeft=!sConf.maxLeft"></uni-icons>
			</view>

			<button @tap="test">test</button>

			<view>
				<view class="user-dropdown" @click.stop="showTopMenu = !showTopMenu">
					<image :src="sConf.cos + localAuth.staff?.face || '/media/default/default_1.png'" mode="aspectFit"
						style="width: 40px; height: 40px;border-radius: 50%;">
					</image>
					<uni-badge :text="localAuth.staff?.is_super?'root':''" absolute="rightTop" :offset="[-10,12]">
						<text class="username">{{ sConf.auth?.nicename || '管理员' }}</text>
					</uni-badge>
					<uni-icons type="down" size="14" :class="{ 'arrow-up': showTopMenu }"
						style="margin-left: 50px;"></uni-icons>
				</view>

				<view class="dropdown-menu" v-show="showTopMenu" @click.stop>
					<view class="menu-item" @click="handleProfile">
						<uni-icons type="person" size="16"></uni-icons>
						<text>个人信息</text>
					</view>
					<view class="menu-item" @click="handlePassword">
						<uni-icons type="locked" size="16"></uni-icons>
						<text>修改密码</text>
					</view>
					<view class="divider"></view>
					<view class="menu-item logout" @click="handleLogout">
						<uni-icons type="upload" size="16" style="transform: rotate(-90deg);"></uni-icons>
						<text>退出登录</text>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import psMethod from '@/utils/psMethod.js';
	export default {
		data() {
			return {
				title: '顶部标题栏',
				sConf: getApp().globalData,
				localAuth: null,
				showTopMenu: false
			}
		},
		mounted() {
			console.log('mounted', this.title);
			let login = psMethod.syncHasLoginToken()
			if (login) {
				this.localAuth = login
			} else {
				psMethod.syncRemoveLoginToken()
			}
		},
		methods: {
			test() {
				console.log(this.localAuth);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-title {
		color: #f1f1f1;
		font-size: 32px;
		font-weight: bold;
	}



	.user-dropdown {
		display: flex;
		align-items: center;
		gap: 10px;
		padding: 5px 10px;
		cursor: pointer;
		border-radius: 4px;

		&:hover {
			background-color: #f5f5f5;
		}

		.username {
			font-size: 14px;
			color: #333;
		}

		.arrow-up {
			transform: rotate(180deg);
		}
	}

	.dropdown-menu {
		position: fixed;
		top: 64px;
		right: 0;
		width: 200px;
		background-color: #fff;
		box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
		border-radius: 4px;
		padding: 5px 0;
		z-index: 999;

		.menu-item {
			display: flex;
			align-items: center;
			gap: 10px;
			padding: 10px 15px;
			font-size: 14px;
			cursor: pointer;

			&:hover {
				background-color: #f5f5f5;
			}

			&.logout {
				color: #ff4d4f;
			}
		}

		.divider {
			height: 1px;
			background-color: #f0f0f0;
			margin: 5px 0;
		}

	}
</style>